// game project main.go

// aggro: aggressive monster
// MOB: vom comp gesteuert (Mob, npc)

package main

import (
	"fmt"
	"log"
	"math/rand"
	"time"
)

var world = NewWorld()

func main() {

	rand.Seed(time.Now().Unix())

	log.Print("----------------------------------")

	place := &Coords{0, 0}
	startPlace := world.Place(place)
	heiko := NewHuman("Heiko", startPlace)
	startPlace.put(heiko)

	apple := &Food{Item: Item{name: "apple"}, energy: 30}
	startPlace.put(apple)
	apple.location = startPlace

	pearTree := Tree{Item: Item{name: "pear tree", location: startPlace}}
	startPlace.put(pearTree)

	person := NewHuman("Eckat", startPlace)
	startPlace.put(person)

	log.Printf("items on start place: %+v\n\n", startPlace.items)

	startTextUI(heiko)

	//	berry := &Food{Item: Item{name: "berry"}, energy: 10}
	//	heiko.Bag(berry, 1)
	// heiko.eat("berry")
	/*
		m := NewMage("fiete")
		w := NewWarrior("hein")

		BattleToTheEnd(&m, &w)
		fmt.Printf("%v", m)
		fmt.Printf("%v", w)
	*/
}

type Item struct {
	name     string
	location *Place
}

func NewItem(name string, location *Place) Item {
	return Item{name, location}
}

// implements Entity
func (this Item) Name() string {
	return this.name
}

// implements Entity
func (this Item) Description() string {
	return fmt.Sprintf("This is %s.", this.Name())
}

// implements MovableObject
func (this Item) Location() *Place {
	return this.location
}

func (this Item) Put(location *Place) {
	this.location = location
}

// implements fmt.Stringer
func (this Item) Stringfff() string {
	return fmt.Sprintf("Item with name %v", this.name)
}

type Food struct {
	Item
	weight int
	energy int
}

func (this Food) Energie() int {
	return this.energy
}

func (this Food) Weight() int {
	return this.weight
}

type Animal struct {
	Creature
}

func NewAnimal() *Animal {

	return &Animal{Creature{isAlive: true, energy: 200, tiredness: 0}}

}

type Tree struct {
	Item
}

func (this *Tree) harvest() Portable {

	return &Food{Item: Item{name: "pear"}, energy: 40}

}

/*)
type ActiveCharacter struct {
	Name         string
	xp           int
	intelligence int

	maxHp int
	hp    int

	maxMana int
	mana    int

	ap int
	dp int
}

type NPC struct {
	Name string
}

type Character struct {
	ActiveCharacter
}

type Mob struct {
	ActiveCharacter
}

type Fighter interface {
	HP()
	Mana()
	GetHit(f Fighter)
	Hit(oppenent Fighter)
	IsDead() bool
}

type Inventory struct {
	owner Character
}

type Item struct {
	Name string
}

type Weapon struct {
	Item
	ap int
}

type Armor struct {
	Item
	dp int
}

type Trader interface {
	requestTrade(t Trader)
	acceptTradeRequest(t Trader)
	rejectTradeRequest(t Trader)
}

type Trade struct {
}

func (this *ActiveCharacter) GetHit(attacker Fighter) {
	this.hp = this.hp - attacker.Hit()
	if this.hp < 0 {
		this.hp = 0
	}
	return
}

func (this ActiveCharacter) Hit() int {
	return this.ap
}

func (this ActiveCharacter) IsDead() bool {
	return this.hp == 0
}

func NewWarrior(name string) Character {

	return Character{ActiveCharacter{Name: name, hp: 100, ap: 10}}

}

func NewMage(name string) Character {

	return Character{ActiveCharacter{Name: name, hp: 85, ap: 12}}

}

func BattleToTheEnd(f1 Fighter, f2 Fighter) {

	for {
		f2.GetHit(f1)
		if f2.IsDead() {
			break
		}
		f1.GetHit(f2)
		if f1.IsDead() {
			break
		}
	}
	return
}
*/
